home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "StringHelpers"
- Option Explicit
-
- Public Function Str_Replace(ByRef s$, ByVal name$, ByVal val$) As Boolean
- Str_Replace = False
- Dim pos&
- pos = InStr(s, name)
- If (pos > 0) Then
- Dim nameLen%
- nameLen = Len(name)
- s = Left(s, pos - 1) + val + Mid(s, pos + nameLen)
- Str_Replace = True
- End If
- End Function
-
- Public Function Str_ReplaceAll(ByRef s$, ByVal name$, ByVal val$) As Boolean
- Str_ReplaceAll = False
- Do
- Dim bReplaced As Boolean
- bReplaced = Str_Replace(s, name, val)
- If Not bReplaced Then Exit Do
- Str_ReplaceAll = True
- Loop
- End Function
-
- Public Function Str_Token(ByVal s$, ByVal sep$, ByVal Item%)
- Dim s0$, pos1&, pos2&
-
- s0 = ""
- Str_Token = ""
- pos2 = 0
- Do While Item >= 0
- s0 = ""
- pos2 = InStr(s, sep)
- If (pos2 = 0) And (Item <> 0) Then Exit Do
-
- If pos2 = 0 Then
- s0 = s
- Else
- s0 = Left(s, pos2 - 1)
- End If
- s = Mid(s, pos2 + 1)
- Item = Item - 1
- Loop
- Str_Token = s0
- End Function
-
- '----------------------------------------------------------------------
- ' Returns copy of the specified string without leading and trailing
- ' whitespace characters
- '----------------------------------------------------------------------
- Public Function Str_Trim(s$) As String
- Str_Trim = Str_TrimEx(s, " " & Chr(9) & Chr(10) & Chr(13))
- End Function
-
- '----------------------------------------------------------------------
- ' Returns copy of the specified string without leading and trailing
- ' characters specified in sWhat$
- '----------------------------------------------------------------------
- Public Function Str_TrimEx(s$, sWhat$) As String
- Dim nSize&, nFirst&, nLast&
-
- Str_TrimEx = ""
-
- ' Find first non whitespace character
- nSize = Len(s)
- nFirst = 1
- Do
- If (InStr(sWhat, Mid(s, nFirst, 1)) = 0) Then Exit Do
- nFirst = nFirst + 1
- If (nFirst > nSize) Then Exit Function
- Loop
-
- ' Find last non whitespace character
- nLast = nSize
- Do
- If (InStr(sWhat, Mid(s, nLast, 1)) = 0) Then Exit Do
- nLast = nLast - 1
- If (nLast < nFirst) Then Exit Function
- Loop
-
- Str_TrimEx = Mid(s, nFirst, nLast - nFirst + 1)
- End Function
-
-